package com.flyoil.petromp.adapter.adapter_notice;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.BaseRecyAdapter;
import com.flyoil.petromp.entity.entity_notice.NoticeEntity;

/**
 * Created by songzhiiyn on 2017/10/11.
 * 公告列表的适配器
 */

public class ItemNoticeAdapter extends BaseRecyAdapter<ItemNoticeAdapter.ViewHoder, NoticeEntity.DataBean.ListBean> {
    public ItemNoticeAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHoder(mInflater.inflate(R.layout.item_notice_adapter, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHoder viewHoder = (ViewHoder) holder;
        final NoticeEntity.DataBean.ListBean entity = getItemData(position);
        viewHoder.tv_time.setText(entity.getCreatedTimeLabel());
        viewHoder.tv_title.setText(entity.getTitle());
        if (entity.isRead()) {
            viewHoder.img_icon.setVisibility(View.INVISIBLE);
        } else {
            viewHoder.img_icon.setVisibility(View.VISIBLE);
        }
        viewHoder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.Onclick(position, entity);
                }
            }
        });
    }

    class ViewHoder extends RecyclerView.ViewHolder {
        private TextView tv_title;
        private TextView tv_time;
        private ImageView img_icon;
        private LinearLayout line;

        public ViewHoder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_item_notice_adapter_title);
            tv_time = itemView.findViewById(R.id.tv_item_notice_adapter_time);
            img_icon = itemView.findViewById(R.id.img_item_notice_adapter_icon);
            line = itemView.findViewById(R.id.line_item_notice_adapter_layout);
        }
    }
}
